﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using control.Dal;

namespace control.Biz
{
    public class BizKhachHang
    {
        public int ID { get; set; }
        public string MaKhachHang { get; set; }
        public string TenKhachHang { get; set; }
        public string DiaChi { get; set; }
        public string Email { get; set; }
        public string SoDienThoai{ get; set; }
        public string GhiChu { get; set; }
        public string Username { get; set; }
        public string Password { get; set; }
        public string TaiKhoan { get; set; }
        private BizPhanQuyen quyen;
        public BizPhanQuyen Quyen
        {
            set { quyen = value; }
            get
            {
                if (quyen == null)
                    quyen= new BizPhanQuyen();
                return quyen;
            }
        }


        public bool DangNhap()
        {

            BizKhachHang kh = DalKhachHang.DangNhap(this);
            if (kh != null)
            {
                ID = kh.ID;
                MaKhachHang = kh.MaKhachHang;
                TenKhachHang = kh.TenKhachHang;
                DiaChi = kh.DiaChi;
                Email = kh.Email;
                Username = kh.Username;
                Password = kh.Password;
                SoDienThoai = kh.SoDienThoai;
                GhiChu = kh.GhiChu;
                TaiKhoan = kh.TaiKhoan;
                Quyen = kh.Quyen;
            }
            if (this.ID == 0)
                return false;
            else
                return true;
        }
        public string TenQuyen
        {
            get { return quyen.Quyen; }
        }
        public static List<BizKhachHang> GetAll()
        {
            return DalKhachHang.GetAll();
        }
        public bool IsBad
        {
            get
            {
                if (GhiChu == null)
                    return false;
                else
                    return true;
            }
        }
        public static BizKhachHang GetByID(int ID)
        {
            return DalKhachHang.GetByID(ID);
        }

        public bool Detele()
        {
            return DalKhachHang.Delete(this);
        }

        public bool UpDate()
        {
            return DalKhachHang.UpDate(this);
        }

        public bool DangKy()
        {
            return DalKhachHang.Registry(this);
        }

        public static BizKhachHang FindByUsername(string _username)
        {
            return DalKhachHang.FindByUsername(_username);
        }
    }
}
